package com.luck.emp.exp.web;


import org.apache.commons.lang.StringUtils;

import com.luck.emp.entity.EmpTExpress;
import com.luck.emp.exp.logic.IExpLogic;
import com.luck.emp.exp.qry.ExpQry;
import com.luck.pf.common.entity.UserBean;
import com.luck.pf.framework.action.BaseActionSupport;
import com.luck.pf.util.ObjectUtil;
import com.luck.pf.util.Page;

/**
 * 说明:ACTION类
 * Copyright: Copyright (c) 2011
 * 深圳**科技
 * @author 
 * 
 */
public class ExpAction extends BaseActionSupport {
		/**
		 * 逻辑处理类
		 */
		IExpLogic expLogic;
		/**
		 * 查询对象
		 */
		ExpQry qry;
		/**
		 * 分页对象
		 **/
		Page page;
		/**
		 * 实体类
		 */
		EmpTExpress entity;
		
		/**
		 * 列表
		 */
		public String list() throws Exception{
			UserBean userInfo = super.getUserInfo();
		
			if(StringUtils.isNotBlank(super.qryHex)){
				qry = (ExpQry)ObjectUtil.getObjectFromHex(qryHex);
			}
			if(qry==null){
				qry = new ExpQry();
			}
			qry.setUserInfo(userInfo);
			page = expLogic.findExpPage(qry);
			return "list";
		}
		/**
		 * 新增
		 **/
		public String toAdd() throws Exception{
			UserBean userInfo = super.getUserInfo();
			entity = new EmpTExpress();
			super.event="ADD";
			super.title="新增承运商";
			return "edit";
		}
		/**
		 * 修改
		 **/
		public String toEdit() throws Exception{
			UserBean userInfo = super.getUserInfo();
			entity = expLogic.get(EmpTExpress.class,entity.getId());
			super.event="EDIT";
			super.title="修改承运商";
			return "edit";
		}
		/**
		 * 修改动作
		 **/
		public String edit() throws Exception{
			UserBean userInfo = super.getUserInfo();
			if("ADD".equals(super.event)){
				//新增操作
				entity.setId(null);
				expLogic.saveExp(userInfo, entity);
			}else if("EDIT".equals(super.event)){
				//修改操作
				EmpTExpress db = expLogic.get(EmpTExpress.class,entity.getId());
				super.copyProperties(db, entity);
				expLogic.saveExp(userInfo, db);
			}
			super.redirectUrl = "/emp/exp_list.action";
			return super.GLOBAL_SUCCESS;
		}
		/**
		 * 删除
		 **/
		public String delete() throws Exception{		
			UserBean userBean = super.getUserInfo();
			String str = "";
			try {
				str = expLogic.deleteExp(userBean, entity);
			} catch (Exception e) {
				str = e.getMessage();
			}
			if(StringUtils.isNotBlank(str)){
				super.renderJsonError(str);
			}else
				super.renderJsonSuccess("删除成功!");
			return null;
		}
		
		/**
		 * 修改
		 **/
		public String toView() throws Exception{
			UserBean userInfo = super.getUserInfo();
			entity = expLogic.get(EmpTExpress.class,entity.getId());
			super.title="承运商详细信息";
			return "view";
		}
		
		public ExpQry getQry(){
			return this.qry;
		}
		public void setQry(ExpQry qry){
			this.qry = qry;
		}
		
		public IExpLogic getExpLogic(){
			return this.expLogic;
		}
		public void setExpLogic(IExpLogic expLogic){
			this.expLogic = expLogic;
		}
		public Page getPage() {
			return this.page;
		}
		public void setPage(Page page) {
			this.page = page;
		}
		public EmpTExpress getEntity(){
			return entity;
		}
		public void setEntity(EmpTExpress entity){
			this.entity = entity;
		}
}